package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.GoodsBean;
import com.project.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("goods")
public class GoodsController {
    @Autowired
    private IGoodsService service;
@RequestMapping("findByItem")
    public IPage<GoodsBean> findByItem(Integer pageNo , String name, Integer startNum, Integer endNum, Integer price, String genre){
        return service.findByItem(pageNo,name,startNum,endNum,price,genre);
    }
@RequestMapping("findById")
    public GoodsBean findById(Integer number){
    GoodsBean goodsBean = service.findById(number);
    if (goodsBean!=null){
        return goodsBean;
    }
    GoodsBean goodsBean1 = new GoodsBean();
    return goodsBean1;
    }
@RequestMapping("update")
    public String update (Integer id,Integer sellPrice){
    service.update(id,sellPrice);
    return "ok";
    }
    @RequestMapping("findAll")
    public List<GoodsBean> findAll(){
    return service.findAll();
    }

    @RequestMapping("findTypes")
    public Set<String> findTypes() {
        List<GoodsBean> all = findAll();
        HashSet<String> types = new HashSet<>();
        all.forEach(e -> {
            types.add(e.getGenre());
        });
        return types;
    }
}
